﻿Public Class LoaiNhaDAO

    Private connect As ConnectDB
    Private sqlstr As String


    Public Sub New()
        connect = New ConnectDB()
    End Sub

    Public Function IsUpLN(ByVal emp As LoaiNhaDTO, ByVal flag As Boolean)
        Dim IDLN As String = emp.Mã_loại_nhà
        Dim TenLN As String = emp.Tên_loại_nhà

        '-------------------------------------------'
        If flag = True Then
            sqlstr = "INSERT LOAINHA (TenLoaiNha)" & _
                        " VALUES('" & TenLN & "')"
        Else
            sqlstr = "UPDATE LOAINHA SET TenLoaiNha   = '" & TenLN & _
                                    "' WHERE MaLoai  = '" & IDLN & "'"

        End If
        Return connect.Execute(sqlstr)
    End Function

    Public Function DeleteLN(ByVal emp As LoaiNhaDTO)
        Dim IDLN As String = emp.Mã_loại_nhà
        sqlstr = "DELETE LOAINHA WHERE MaLoaiNha = '" & IDLN & "'"
        Return connect.Execute(sqlstr)
    End Function

    Public Function Getdata() As List(Of LoaiNhaDTO)
        Dim i As Integer
        Dim maln, tenln As String
        Dim emp As LoaiNhaDTO
        Dim lnList As New List(Of LoaiNhaDTO)
        Dim dt As New DataTable
        dt = connect.GetData("Select * From LOAINHA")

        For i = 0 To dt.Rows.Count() - 1
            maln = dt.Rows(i)("MaLoai").ToString
            tenln = dt.Rows(i)("TenLoaiNha").ToString

            emp = New LoaiNhaDTO(maln, tenln)
            lnList.Add(emp)
        Next
        Return lnList
    End Function

End Class
